package com.gsit.ocraspect.services;

import java.util.TimerTask;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import com.gsit.ocrbatch.controller.OcrProcesser;
import com.gsit.ocrbatch.domain.Record;
import com.gsit.ocrbatch.utils.AspectState;
import com.gsit.ocrbatch.utils.FileConstant.FileFlow;

@Service
public class BatchService extends TimerTask{
	
	private static final Logger logger = LoggerFactory.getLogger(BatchService.class);
	
	@Autowired
	private OcrProcesser ocrProcesser;
	
	 public void run() {
		 process();
	 }
	
	@Scheduled(fixedDelay=5000)
	public void process(){
		
			try {
				logger.info("Batch process called for process flow");
				ocrProcesser.execute(FileFlow.PROCESS,null);
				ocrProcesser.show();
			} catch (Exception e) {
				logger.error("Error during ocrProcesser.execute",e);
			}
		
	}
	
	public void process(final FileFlow fileFlow,Record record){
		try {
			ocrProcesser.execute(fileFlow, record);
		} catch (Exception e) {
			logger.error("Error during ocrProcesser.execute",e);
		}
	}
	
	public Boolean getCurrentState(){
		return AspectState.getStart();
	}

}
